package com.yifn.diy;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect // 标注这是一个切面
public class DiyPointCut {

    @Before("execution(* com.yifn.service.UserService.*(..))")
    public void before(){
        System.out.println("====before======");
    }

    @After("execution(* com.yifn.service.UserService.*(..))")
    public void after(){
        System.out.println("====after======");
    }

    // 在环绕增强中，可以给定一个参数，代表我们 要获取处理切入的点
    @Around("execution(* com.yifn.service.UserService.*(..))")
    public void around(ProceedingJoinPoint jp){
        System.out.println("环绕前");
        try {
            Object proceed = jp.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }

        System.out.println("环绕后");
    }

}
